<!--
*  2021-03-15
*  成品跟踪  区域汇总
-->
<template>
  <div id="app" class="view-area">
    <!-- 头部导航 -->
    <van-nav-bar
      ref="header"
      :title="title"
      left-arrow
      @click-left="onClickLeft"
      left-text="返回"
    >
    </van-nav-bar>
    <!-- 滚动 -->
    <better-scroll
      class="public-scroll"
      :data="tableData"
      :totalPage="totalPage"
    >
      <van-cell-group v-show="tableData.length !== 0">
        <van-cell
          v-for="(data, index) in tableData"
          :key="index"
          :title="data.area"
          :value="data.num"
        >
          <template slot="label">
            <div class="product-code__cell">
              <p>
                <span>长度: {{ data.length }}</span>
                <span>重量: {{ data.weight }}</span>
              </p>
            </div>
          </template>
        </van-cell>
      </van-cell-group>
      <van-empty
        class="custom-image"
        image="https://img01.yzcdn.cn/vant/custom-empty-image.png"
        v-show="tableData.length === 0"
        description="暂无数据"
      />
    </better-scroll>
  </div>
</template>

<script>
import { openWin } from "@/utils/index";
import { getProductAreaList } from "@/api/product";

export default {
  name: "productViewArea",
  data() {
    return {
      title: "",
      totalPage: 1,
      tableData: [],
      designNo: "",
      keyLike: "",
      color: '',
      isColor: false,
      vatNo: '',
      isVatNo: false
    };
  },
  mounted() {
    const that = this;
    if (process.env.NODE_ENV === "production") {
      this.$nextTick(() => {
        that.initFn(that);
      });
    } else {
      window.apiready = function () {
        that.initFn(that);
      };
    }
  },
  methods: {
    //初始化
    initFn(that) {
      that.designNo = window.api.pageParam.designNo;
      that.isColor = window.api.pageParam.isColor;
      that.color = window.api.pageParam.color;
      that.vatNo = window.api.pageParam.vatNo;
      that.isVatNo = window.api.pageParam.isVatNo;
      that.title = window.api.pageParam.title;
      that.onGetTableData();
      window.api.addEventListener({
        name:'viewdisappear'
      }, function() {
        window.api.closeWin();
      });
    },
    // 返回
    onClickLeft() {
      if (this.isVatNo) {
        openWin("view-vat", {
          designNo: this.designNo,
          scrollY: window.api.pageParam.scrollY,
          keyLike: window.api.pageParam.keyLike
        });
      } else if (this.isColor) {
        openWin("view-color", {
          designNo: this.designNo,
          scrollY: window.api.pageParam.scrollY,
          keyLike: window.api.pageParam.keyLike
        });
      } else {
        openWin("product-view", {
          scrollY: window.api.pageParam.scrollY,
          keyLike: window.api.pageParam.keyLike
        });
      }
    },
    // 成品区域汇总
    onGetTableData() {
       let params = {}
       params.otherStock = ''
      if (this.designNo) {
        params.designNo = this.designNo
      }
      if (this.isColor) {
        params.color = this.color
      }
      if (this.isVatNo) {
          params.vatNo = this.vatNo
      }
      this.tableData = [];
      getProductAreaList(params, (res) => {
        this.tableData = res;
      });
    },
    onClickSearch() {
      this.onGetTableData();
    },
  },
};
</script>

<style lang="scss">
.view-area {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .van-search {
    width: 100%;
    position: relative;
    z-index: 999;
  }
  .van-cell__title {
      flex: 0 0 70%;
      .product-code__cell {
        width: 100%;
        display: flex;
        flex-direction: column;
        p {
          width: 100%;
          height: 30px;
          display: flex;
          justify-content: space-between;
          span {
            flex: 1;
            display: flex;
            align-items: center;
            &:last-child {
              justify-content: flex-end;
            }
          }
        }
      }
    }
  .public-scroll {
    flex: 1;
    overflow: hidden;
  }
}
</style>
